package com.gxa.service.impl;

import com.gxa.common.PaginationResult;
import com.gxa.mapper.AnnMapper;
import com.gxa.pojo.Announcement;
import com.gxa.pojo.Employee;
import com.gxa.pojo.Role;
import com.gxa.service.AnnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: zrf
 * Date: 2020/10/29 9:38
 * Description:
 * Version: V1.0
 */
@Service
public class AnnServiceImpl implements AnnService {
    @Autowired(required = false)
    private AnnMapper annMapper;

    /**
     * 增加公告
     *
     * @param announcementTitle,announcementDescribe
     * @return 实例对象
     */
    @Override
    public int addAnn(String announcementTitle,String announcementDescribe,Integer employee_id) {


        return annMapper.addAnn(announcementTitle,announcementDescribe,employee_id);
    }
    /**
     * 查询未发布公告
     *
     * @param
     * @return 实例对象
     */
    @Override
    public PaginationResult selAnnUn(Integer currentPage, Integer pageSize) {
        PaginationResult paginationResult = new PaginationResult();
        int parm1 = (currentPage - 1) * pageSize;
        paginationResult.setData(annMapper.selAnnUn(parm1,pageSize));
        paginationResult.setCurrentPage(parm1);
        paginationResult.setPageSize(pageSize);
        int total = annUnCont() / pageSize;
        System.out.println(annUnCont());
        if(annUnCont() % pageSize != 0){
            total+=1;
        }
        System.out.println(total);
        paginationResult.setTotalPage(total);
        paginationResult.setTotalSize(annUnCont());
        return paginationResult;
    }

    /**
     * 查询已经发布公告
     *
     * @param currentPage,pageSize
     * @return 实例对象
     */
    @Override
    public PaginationResult selAnn(Integer currentPage, Integer pageSize) {
        PaginationResult paginationResult = new PaginationResult();
        int parm1 = (currentPage - 1) * pageSize;
        paginationResult.setData(annMapper.selAnn(parm1,pageSize));
        paginationResult.setCurrentPage(parm1);
        paginationResult.setPageSize(pageSize);
        int total = annUnCont() / pageSize;
        System.out.println(annCont());
        if(annUnCont() % pageSize != 0){
            total+=1;
        }
        System.out.println(total);
        paginationResult.setTotalPage(total);
        paginationResult.setTotalSize(annCont());
        return paginationResult;
    }

    /**
     * 发布公告
     *
     * @param announcementId
     * @return 实例对象
     */
    @Override
    public int updateAnnId(Integer announcementId) {


        return annMapper.updateAnnId(announcementId);
    }

    /**
     * 编辑公告
     *
     * @param announcement
     * @return 实例对象
     */
    @Override
    public int updateAnn(Announcement announcement) {
        return annMapper.updateAnn(announcement);
    }
    /**
     * 删除公告
     *
     * @param announcementId
     * @return 实例对象
     */
    @Override
    public int delAnnById(int announcementId) {
        return annMapper.delAnnById(announcementId);
    }

    /**
     * 根据员工id查询员工信息
     *
     * @param employeeId
     * @return int
     */
    @Override
    public Employee selEmploy(Integer employeeId) {
        Employee employee = annMapper.selEmploy(employeeId);
        List<Role> roleList = selRole(employeeId);
        employee.setRoleList(roleList);
        return employee;
    }
    /**
     * 根据员工id查询员工角色信息信息
     *
     * @param employeeId
     * @return int
     */
    public List<Role> selRole(Integer employeeId){
        return annMapper.selRole(employeeId);
    }

    /**
     * 查询未发布公告总数
     *
     * @param
     * @return 实例对象
     */
    private int annUnCont(){
        return annMapper.annUnCont();
    }
    /**
     * 查询已经发布公告总数
     *
     * @param
     * @return 实例对象
     */
    private int annCont(){
        return annMapper.annUnCont();
    }

}
